﻿using System.Collections.Generic;
using System.Linq;
using ZFine.Code;
using ZFine.Domain.Entity;
using ZFine.Domain.IRepository.Project;
using ZFine.Repository.Project;

namespace ZFine.Application.Project
{
    public class InformMessagesApp
    {
        private IInformMessagesRepository service = new InformMessagesRepository();

        public List<InformMessagesEntity> GetList()
        {
            return service.IQueryable().ToList();
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public InformMessagesEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        public void DeleteForm(string keyValue)
        {
            var local = service.FindEntity(keyValue);
            service.DeleteForm(keyValue);
            //if (local != null)
            //{
            //    local.State = false;
            //    return service.Update(local);
            //}
            //else
            //{
            //    return -1;
            //}
        }

        #region 商户-消息
        public List<InformMessagesEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<InformMessagesEntity>();
            expression = expression.And(t => t.Type == 1);
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.Title.Contains(keyword));
            }
            expression = expression.And(t => t.State == true);
            return service.FindList(expression, pagination);
        }
        /// <summary>
        /// 群发送
        /// </summary>
        public void SubmitFormC(InformMessagesEntity MemberEntity)
        {
            MemberEntity.Create();//创建ID与添加时间
            MemberEntity.State = true;
            MemberEntity.Type = 1;
            //service.Insert(MemberEntity);
            service.SubmitFormSendC(MemberEntity);

        }
        #endregion

        #region 会员-消息

        public System.Collections.Generic.List<InformMessagesEntity> GetListM(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<InformMessagesEntity>();
            expression = expression.And(t => t.Type == 2);
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.Title.Contains(keyword));
            }
            expression = expression.And(t => t.State == true);
            return service.FindList(expression, pagination);
        }
        /// <summary>
        /// 群发送
        /// </summary>
        public void SubmitFormM(InformMessagesEntity MemberEntity)
        {
            MemberEntity.Create();//创建ID与添加时间
            MemberEntity.State = true;
            MemberEntity.Type = 2;
            //service.Insert(MemberEntity);
            service.SubmitFormSendM(MemberEntity);

        }
        #endregion
    }
}
